<!--
 * @Author: your name
 * @Date: 2022-01-24 21:12:13
 * @LastEditTime: 2022-01-24 22:40:59
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \json-serveg:\桌面2\VueStudy\vue-ego\vue-ego\src\views\Goods\TreeGoods.vue
-->
<template>
  <div>
      <el-tree
        :props="props"
        :load="loadNode"
        lazy
        accordion
        @node-click='nodeClick'
        >
        </el-tree>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        props: {
          label: 'name',
          children: 'zones',
          isLeaf: 'leaf'
        },
      };
    },
    methods: {
      loadNode(node, resolve) { // resolve成功的返回数据结果
    //   console.log(node)
        if (node.level === 0) {
            //进入页码获取第一次tree数据
            this.$api.getSearchCategory().then((res) => {
                // console.log(res.data)
                return resolve(res.data.result);
            }) 
        }
        if (node.level >= 1) {
                // console.log(node);
            this.$api.getSearchCategory(
                {id:node.data.cid}
            ).then((res) => {
                if(res.data.status===200){
                  return resolve(res.data.result);
              }else{
                  return resolve([])
              }
            }) 
        }

        
      },
    //获取选择分类的参数
    nodeClick(data){
        // console.log('@@@@@',data);
        this.$emit('CateName',data)
    }

    }
  };
</script>


<style>

</style>
